//
//  JWNicknameVC.m
//  jinwang
//
//  Created by jzb on 2018/3/9.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "JWNicknameVC.h"

@interface JWNicknameVC ()
{
    UITextField *_NicknameTF;
}
@property (nonatomic,strong) UIButton *preserveBtn;

@end

@implementation JWNicknameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"昵称";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem *preserveItem = [[UIBarButtonItem alloc]initWithCustomView:self.preserveBtn];
    self.navigationItem.rightBarButtonItem = preserveItem;

    
    _NicknameTF = [[UITextField alloc]initWithFrame:CGRectMake(45/2, 160/2, kScreenWidth-90/2, 70/2)];
    
    _NicknameTF.font = [UIFont systemFontOfSize:17];
    
    _NicknameTF.placeholder = @"请填写您的昵称";
    
    if (kStringIsEmpty(k_user_nickname)) {
        _NicknameTF.placeholder = @"请填写您的昵称";
    }else{
        _NicknameTF.text = k_user_nickname;
    }
    
    [self.view addSubview:_NicknameTF];
    
    UIView *view = [[UIView alloc] init]; 
    view.frame = CGRectMake(30/2,230/2,kScreenWidth-30,1);
    view.backgroundColor = kRGBColor(204, 204, 204);
    
    [self.view addSubview:view];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(45/2,250/2,kScreenWidth-45,40/2);
    label.text = @"好名字可以让你的朋友更容易记住你";
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = kRGBColor(188, 188, 188);
    
    [self.view addSubview:label];
}

#pragma mark -懒加载
- (UIButton *)preserveBtn{
    if (!_preserveBtn) {
        _preserveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _preserveBtn.frame = CGRectMake(0, 0, 44, 44);
        [_preserveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [_preserveBtn addTarget:self action:@selector(preserveButOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _preserveBtn;
}

- (void)preserveButOnclick:(UIButton *)sender{
    
    if (kStringIsEmpty(_NicknameTF.text)) {

        [self showBottomMessag:@"请填写您的昵称"];

    }else{
        
        [self net_makeUrl_setUserInfo];
    }
}
#pragma mark -网络请求

-(void)net_makeUrl_setUserInfo{
    [[DDNetworkManagerDate makeUrl_setUserInfo_with_token:k_user_token user_nickname:_NicknameTF.text user_sex:nil user_sign:nil user_portrait:nil] post_RequestFinshSuccess:^(id responseObject) {
        
        if ([self requestFinshCode:responseObject isShowMessage:YES] == 1) {
            [kUserDefaults setObject:_NicknameTF.text forKey:@"user_nickname"];

            [self goBack];
        }
        
    } failure:^(id errorObject) {
        [self showBottomMessag:@"网络请求失败"];
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
